package main

func majorityElement(nums []int) int {
	ele := -1
	count := 0

	for i := 0; i < len(nums); i++ {
		if count == 0 {
			ele = nums[i]
			count++
		} else {
			if ele == nums[i] {
				count++
			} else {
				count--
			}
		}
	}
	count = 0

	for i := 0; i < len(nums); i++ {
		if nums[i] == ele {
			count++
		}
	}

	if count > int(len(nums)/2) {
		return ele
	}

	return -1

}

func countElements(nums []int) int {
	for i := 0; i < len(nums); i++ {

		isFind := false

		for j := 0; j < len(nums); j++ {
			if nums[j] < nums[i] {
				isFind = true
				break
			}
		}

		if !isFind {
			continue
		}

		isFind = false
		for j := 0; j < len(nums); j++ {
			if nums[j] > nums[i] {
				isFind = true
				break
			}
		}

		if isFind {
			return nums[i]
		}
	}

	return -1
}
